package com.bb;

public class ByteTest {


    public static void main (String args[])
            throws  Exception {

        testIntToByte();
//        System.out.println( Integer.toHexString(-3) );
//        System.out.println( Integer.toBinaryString(-3) );
//        System.out.println( ":::: getSlot 111 index ::: " + index + " i == " + i  );

        byte slotByte = -1 ;
        int pos = 2 ;
        System.out.println( Integer.toBinaryString(-1) );
        System.out.print("=====  设置0 =======");

        int a =  slotByte & ~(1 << pos) ;
        System.out.println(  a + "==" +  Integer.toHexString(a) );
        System.out.println( Integer.toBinaryString(a) );
        System.out.println( "====== ByteTest ===== " +  ByteTest.getByte( (byte)a , 2) );
        slotByte = -5 ;
        System.out.print("=====  设置1 =======");
        int b = slotByte | (1 << pos)  ;
        System.out.println( b + "==" + Integer.toHexString(b) );
        System.out.println( Integer.toBinaryString(b) );

//        int b = slotByte | (1 << pos)  ;


    }

    private static void  testIntToByte(){
        int i = 234;
        byte b = (byte) i;
        System.out.println(b); // -22
        int i2 = b & 0xFF;
        System.out.println(i2); // 234
    }



    static int getByte( byte b,int bit) {
        if( bit < 0 || bit > 7)
            return 0;
        return ( b & (0b1 << bit)) > 0 ? 1: 0;
    }


}
